package com.dhcc.hikari.util.thread.callable;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import com.dhcc.hikari.util.thread.callable.ThreadPoolWithcallable.ThreadPoolByCallable;

/**
 * 
* <p>标题: TestCallable.java</p>
* <p>业务描述:健康管理平台</p>
* <p>公司:东华软件股份公司</p>
* <p>版权:dhcc2013</p>
* @author 胡凯
* @date Nov 27, 2018
* @version V1.0
 */
public class TestCallable {
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		Future<?> submit = null;
		ArrayList<Future<?>> results = new ArrayList<Future<?>>();
		ThreadPoolByCallable pool = ThreadPoolWithcallable.getInstance();
		for(int i=0;i<30;i++) {
			submit = pool.submit(new TaskCallable(i));
			results.add(submit);
		}
		//打印结果
		for(Future f: results){
			boolean done = f.isDone();
			System.out.println(done?"已完成":"未完成");  //从结果的打印顺序可以看到，即使未完成，也会阻塞等待
			System.out.println("线程返回future结果： " + f.get());
		}
		//线程池关闭，项目中一般不关闭
		pool.shutdown();
	}

}
